package com.eagle.functioninterface;

import org.junit.Test;

import java.util.Objects;
import java.util.function.Consumer;

/**
 * {@link java.util.function.Consumer} 函数式接口 是一个从有到无的过程
 * 这点跟{@link java.util.function.Supplier} 是相反的
 *
 * @author qinlinsen
 */
public class ConsumerTest7 {
    @Test
    public void testConsumer() {

        consumer(3, x -> System.out.println(x));

        System.out.println("-------------------------------------------");
        consumer("hello world", item -> {
            final StringBuffer appender = new StringBuffer();
            appender.append(item);
            System.out.println(appender.toString());
        });

    }

    private <T> void consumer(T independentVariable, Consumer<T> consumer) {
        Objects.requireNonNull(independentVariable);
        Objects.requireNonNull(consumer);
        consumer.accept(independentVariable);
    }


}
